<template>
    <div>
        <c-header :p-title="'全部参会人员'">
            <div class="d-flex justify-content-end align-items-center">
                <button class="btn btn-sm btn-primary m-r-sm" @click="importFile">导入酒店更新</button>
                <button type="button" class="btn btn-sm btn-info d-lg-block"  @click="$router.go(-1)"><i class="fa fa-mail-reply m-r-sm"></i>返回</button>
                <btn-refresh class='m-l-15' :p-data='init'></btn-refresh>
            </div>
            <div slot="next" class="col-md-12">
                <span class="m-r-md">人数： {{total_customer}}</span>
                <span>最后更新时间： {{last_update}}</span>
            </div>
        </c-header>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div class="panel-heading  search-heading">
                            <small class="text-muted">搜索筛选项：</small>
                            <div class="m-b-sm">
                                <form class="clearfix" action="javascript:void(0)">
                                    <div class="pull-left m-r m-b-sm">
                                        <label class="control-label">姓名：</label>
                                        <Input class='thumb-search' v-model="search.name" placeholder="请输入姓名"/>
                                    </div>
                                    <div class="pull-left m-r m-b-sm">
                                        <label class="control-label">电话：</label>
                                        <Input class='thumb-search' v-model="search.phone" placeholder="请输入电话"/>
                                    </div>
                                    <div class="pull-left m-r m-b-sm">
                                        <label class="control-label">公司名称：</label>
                                        <Input class="thumb-search" v-model="search.organization" placeholder="请输入公司名称" />
                                    </div>
                                    <div class="pull-left m-r m-b-sm">
                                        <label class="control-label">状态：</label>
                                        <status-select class='thumb-search' :p-data="search.status" :p-name="'people_status'" :p-far='true'  @on-change='searchSelectStatus'></status-select>
                                    </div>
                                    <div class="pull-left w100 text-right">
                                        <button class="btn btn-sm btn-primary m-r-sm" @click="exportFile">导出文档</button>
                                        <button class="btn btn-sm btn-info" type="button" @click="searchChange()">搜索</button>
                                        <Tooltip content="重置默认搜索项" placement="top">
                                            <button class="btn btn-sm btn-dark" type="button" @click="searchReset(true)">重置</button>
                                        </Tooltip>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <hr>
                        <div class="table-responsive"  v-if='list'>
                            <rich-table
                                    :p-data='list'
                                    :p-edit="true"
                                    :p-select="false">
                                <div class="table-edit-group" slot="eidt" slot-scope="slotProps">
                                    <button class="btn btn-sm btn-info" type="button" @click="editDetail(slotProps.item,true)">更新信息</button>
                                </div>
                            </rich-table>
                            <div  v-show='!list.length' class="text-center m-b-sm">
                                暂无数据！
                            </div>
                        </div>
                        <hr/>
                        <footer class="panel-footer">
                            <CPage class="pull-right" :total="search.page_total"
                                   :current='search.page_current'
                                   :page-size='search.page_row'
                                   @on-change='pageCurrentChange'
                                   @on-page-size-change='pageRowChange'>
                            </CPage>
                        </footer>
                    </div>
                </div>
            </div>
        </div>
        <operate-import ref="operate_import" @on-change="initSubmit"></operate-import>
        <operate-save ref="operate_save" @on-change="initSubmit"></operate-save>
    </div>
</template>
<script>
    import serWorkerHotel from '../../serves/api-worker-hotel'
    import operateImport from './OperateUpdateImport'
    import operateSave from './../customer/saveHotel'
    import richTable from './../customer/RichTable'
    const __page_key = 'worker.hotel.customer.list';
    let searchDef = {
        name:'',
        phone:'',
        status:'1',
        organization:'',
        page_row:'',
        page_current:'',
        page_total:''
    };
    export default{
        components:{
            richTable,
            operateImport,
            operateSave,
        },
        data(){
            return{
                total_customer:0,
                last_update:'',
                list:undefined,
                search:{},
                selList:[]
            }
        },
        computed:{
        },
        beforeMount(){
            this.searchReset();
        },
        mounted(){
            this.init();
        },
        methods:{
            searchReset(update,pageState){
                if(pageState){
                    this.$clientPage.def(this.search);
                    return false
                }
                const _p=this.$clientPage.getData(__page_key);
                if(_p){
                    this.$set(this,'search',_p);
                }else{
                    this.$set(this,'search',Object.assign({},searchDef));
                    this.$clientPage.def(this.search);
                }
                if(update){
                    this.init();
                }
            },
            searchPage(page){
                this.$clientPage.set(this.search,page);
            },
            searchChange(){
                this.$clientPage.def(this.search);
                this.init();
            },
            pageRowChange(num){
                if(num!= this.search.page_row){
                    this.$set(this.search,'page_row',num);
                    if(this.search.page_current == 1){
                        this.init();
                    }
                }
            },
            pageCurrentChange(current){
                if(current!= this.search.page_current){
                    this.$set(this.search,'page_current',current);
                    this.init();
                }
            },
            linkPageChange(name,params,query){
                this.$clientPage.setData(__page_key,Object.assign({},this.search));
                if(name){
                    this.$router.push({name:name,params:params,query:query})
                }
            },
            //------------------------------------------------------------------------
            async init(data){
                let res = await serWorkerHotel.customerList({
                    page:this.search.page_current,
                    size:this.search.page_row,
                    name:this.search.name,
                    phone:this.search.phone,
                    status:this.search.status,
                    organization:this.search.organization,
                });

                this.selList = [];
                this.total_customer = res.addtion_data&&res.addtion_data.total_come||0;
                this.last_update = res.addtion_data&&res.addtion_data.last_update||'';
                if(res.code==1){
                    this.list = res.data||[];
                    this.searchPage(res.addtion_data&&res.addtion_data.page_info);
                }else{
                    this.list = [];
                    this.searchReset(undefined,true);
                    this.$Message.error(res.message);
                }
                return true;
            },
            searchSelectStatus(value){
                this.$set(this.search,'status',value);
            },
            initSubmit(state){
                if(state){
                    this.init()
                }
            },
            editDetail(data,edit){
                this.$refs['operate_save'].handleOpen(Object.assign({_type:edit?'edit':'add'},data))
            },
            exportFile(){
                serWorkerHotel.exportFile(this.search);
            },
            importFile(){
                this.$refs['operate_import'].handleOpen({})
            },
        }
    }
</script>